import TileLayer from "ol/layer/Tile"
import TileArcGISRest from 'ol/source/TileArcGISRest'
import OSM from "ol/source/OSM"
import XYZ from 'ol/source/XYZ'

import ol from 'openlayers'
 
let maptype=2          //0表示部署的离线瓦片地图，1表示OSM,2表示使用Arcgis在线午夜蓝地图服务
 
var streetmap=function(){
    var maplayer=null;
    switch(maptype){
        case 0:
            maplayer=new TileLayer({
                source: new XYZ({
                    url:'http://127.0.0.1:7080/streetmap/shenzhen/{z}/{x}/{y}.jpg'
                })
            })
        break;
        case 1:
            maplayer=new TileLayer({
                source: new OSM()
            })
        break;
        case 2:
            maplayer=new TileLayer({
                source:new TileArcGISRest({
                    url:'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer'
                })
            })
        break;
    }
    return [maplayer];
}

let imgBaseUrl = "";
 
let mapconfig={
    mapCfg: {
        center: [112.964083, 28.1953], //中心点经度和纬度
        zoom:12,          //地图缩放级别
        streetmap:streetmap
    },
    mapInteractionCfg:{ //地图交互配置 可参考ol.interaction.defaults参数配置
        doubleClickZoom: false
    },

    layers:[
        {
          title: '图层信息',
          icon: imgBaseUrl,
          layers: [
            {
              source: 'Vector',
              title: '政区底图',
              visible: true,
              style: new ol.style.Style({ image: new ol.style.Icon({ "src": imgBaseUrl + "icon" }) }),
              format: new ol.format.GeoJSON(),
              zIndex: 1,
              id:"id001",
            },

            {
                source: 'Vector',
                title: '边界',
                visible: true,
                style: new ol.style.Style({ image: new ol.style.Icon({ "src": imgBaseUrl + "icon" }) }),
                format: new ol.format.GeoJSON(),
                zIndex: 2,
                id:"id002",
              },
            
          ]
    
        },

        {
            title: '底图url',
            icon: imgBaseUrl + 'icon',
            isHide: true,
            layers: [
              {
                source: 'arctile',
                title: '政区图',
                visible: true,
                projection: 'EPSG:3857',
                url: 'http://218.77.42.151:8000/arcgis/rest/services/map/hnnewmap/MapServer'
              },
            //   {
            //     title: '影像图',
            //     url: 'http://t0.tianditu.com/img_w/wmts',
            //     layer: 'img',
            //     matrixSet: 'w',
            //     source: "TDTTile",
            //     visible: true
            //   }
      
            ]
        }
    ],

    clickLayers:[
        { layerName: '政区地图', feildName: 'STNM', titleField: 'STNM',isOne:true, type: 1, onePre:[{content:'flood',type:1}] },
        { layerName: '城市', feildName: 'ADNM', titleField: 'ADNM',isOne:true, type: 2, onePre:[{content:'flood',type:2}] },
        { layerName: '市边界', feildName: 'STCD', titleField: 'STNM',isOne:true, type: 3, onePre:[{content:'flood',type:3}] },
        { layerName: '县边界', feildName: 'STCD', titleField: 'STNM',isOne:true, type: 4, onePre:[{content:'flood',type:4}] },
    ]

};
 
export default mapconfig